//
//  MBProgressHUD+Manager.m
//  商互通
//
//  Created by 吴志勇 on 16/11/4.
//  Copyright © 2016年 sdy. All rights reserved.
//

#import "MBProgressHUD+Manager.h"

@implementation MBProgressHUD (Manager)

+ (void)show:(NSString *)text {
    [self show:text icon:nil view:nil];
}

/**
 *  显示信息
 *
 *  @param text 信息内容
 *  @param icon 图标
 *  @param view 显示的视图
 */
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    [self hideHUDForView:view];

    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
   //  hud.labelText = text;
    hud.label.text = text;
    
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
   //   [hud hide:YES afterDelay:1];
    
    [hud hideAnimated:YES afterDelay:1];
    
}


+ (void)showtext:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    [self hideHUDForView:view];
    
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
   //  hud.labelText = text;
    hud.label.text = text;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    //[hud hide:YES afterDelay:2];
    [hud hideAnimated:YES afterDelay:2];
}


/**
 *  显示成功信息
 *
 *  @param success 信息内容
 */
+ (void)showSuccess:(NSString *)success
{
    [self showSuccess:success toView:nil];
}

/**
 *  显示成功信息
 *
 *  @param success 信息内容
 *  @param view    显示信息的视图
 */
+ (void)showSuccess:(NSString *)success toView:(UIView *)view
{
    [self show:success icon:@"success.png" view:view];
}

/**
 *  显示错误信息
 *
 */
+ (void)showError:(NSString *)error
{
    [self showError:error toView:nil];
}

/**
 *  显示错误信息
 *
 *  @param error 错误信息内容
 *  @param view  需要显示信息的视图
 */
+ (void)showError:(NSString *)error toView:(UIView *)view{
    [self show:error icon:@"error.png" view:view];
}

/**
 *  显示错误信息
 *
 *  @param message 信息内容
 *
 *  @return 直接返回一个MBProgressHUD，需要手动关闭
 */
+ (MBProgressHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}

/**
 *  显示一些信息
 *
 *  @param message 信息内容
 *  @param view    需要显示信息的视图
 *
 *  @return 直接返回一个MBProgressHUD，需要手动关闭
 */
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  //   hud.labelText = message;
    hud.label.text = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
   //  hud.dimBackground = NO;
   //  hud displayLayer:<#(nonnull CALayer *)#>
    return hud;
}

+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view  mobanshezhi:(BOOL)boor {
    
    
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  //   hud.labelText = message;
    hud.label.text = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
  //   hud.dimBackground = NO;
   hud.backgroundColor = [UIColor whiteColor];
 //    hud.backgroundColor
    return hud;
    
    
    
}





//+ (MBProgressHUD *)createLoadingAnimationViewtoView:(UIView *)view {
//    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
//    // 快速显示一个提示信息
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
//    hud.color = [UIColor clearColor];
//    UIView *custumView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 155, 114)];
//    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, custumView.frame.size.width, custumView.frame.size.height)];
//    UIImageView *animationImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 75, 57)];
//    NSMutableArray *array_image = [[NSMutableArray alloc] init];
//    for (int i = 1; i<=4 ; i++) {
//        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"Refreshloading_xiaoche%d",i]];
//        [array_image addObject:image];
//    }
//    animationImage.animationDuration = 0.75;
//    animationImage.animationImages = array_image;
//    [animationImage startAnimating];
//    [custumView addSubview:bgView];
//    [custumView addSubview:animationImage];
//
//    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(85, 0, 75, 57)];
//    titleLabel.text = @"正在加载...";
//    titleLabel.font = SYS_FONT(14);
//    titleLabel.textColor = LIGHTGREY;
//    [custumView addSubview:titleLabel];
//
//    hud.mode = MBProgressHUDModeCustomView;
//    hud.customView = custumView;
//    // 隐藏时候从父控件中移除
//    hud.removeFromSuperViewOnHide = YES;
//    return hud;
//}


//拍一拍
//+ (MBProgressHUD *)createPaiYiPaiLoadingAnimationViewtoView:(UIView *)view {
//    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
//    // 快速显示一个提示信息
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
//    hud.color = [UIColor clearColor];
//    UIView *custumView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 75+85, view.height)];
////    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, custumView.frame.size.width, 130)];
//    UIImageView *animationImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 65, 75, 57)];
//    NSMutableArray *array_image = [[NSMutableArray alloc] init];
//    for (int i = 1; i<=4 ; i++) {
//        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"Refreshloading_xiaoche%d",i]];
//        [array_image addObject:image];
//    }
//    animationImage.animationDuration = 0.75;
//    animationImage.animationImages = array_image;
//    [animationImage startAnimating];
////    [custumView addSubview:bgView];
//    [custumView addSubview:animationImage];
//    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(85, 65, 75, 57)];
//    titleLabel.text = @"正在加载...";
//    titleLabel.font = SYS_FONT(14);
//    titleLabel.textColor = [UIColor whiteColor];
//    [custumView addSubview:titleLabel];
//
//    hud.mode = MBProgressHUDModeCustomView;
//    hud.customView = custumView;
//    // 隐藏时候从父控件中移除
//    hud.removeFromSuperViewOnHide = YES;
//    return hud;
//}


/**
 *  手动关闭MBProgressHUD
 */
+ (void)hideHUD
{
    [self hideHUDForView:nil];
}

/**
 *  手动关闭MBProgressHUD
 *
 *  @param view    显示MBProgressHUD的视图
 */
+ (void)hideHUDForView:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    [self hideHUDForView:view animated:YES];
}

+ (void)showLoading {
    [self showMessage:@"正在加载..." toView:nil];
}
+ (void)showError {
    [self showError:@"加载失败!"];
}
+ (void)showSuccess {
    [self showSuccess:@"加载成功!"];
}
@end
